<?php
/*
 * 竞彩开奖结果
 */

namespace app\sports\jc\service;

use think\Db;
use think\Exception;
use app\common\HTTP;
use app\common\OSS;
use think\facade\Log;
use app\common\InstanceTrait;
use app\sports\jc\model\JcCaijiModel;

class LineupCaiji
{
    private $user = '';
    private  $secret ='';
//    接口名:竞彩比赛指数
//    接口频次:3-5分钟
    private $url = 'open.sportnanoapi.com/api/v2/sports/jc/odds';

    protected function __construct()
    {
        $this->user = Env::get('nami.user');
        $this->secret = Env::get('nami.secret');
    }

    /*
     * 竞彩开奖结果
     */
    public function Execs()
    {
        try {
            $jcressult = json_decode(HTTP::getInstance()->doGet($this->url."?user=$this->user&secret=$this->secret"), true);
//            竞彩足球开奖结果
            foreach ($jcressult['jczq'] as $value){
                $data=[
                    'result_spf' => $value['spf'],
                    'result_rq' => $value['rf'],

                ];
                JcCaiji::getInstance()->UpdateJc($value['id'],$data);
            }
//            竞彩篮球开奖结果
            foreach ($jcressult['jclq'] as $v){
                $data=[
                    'result_spf' => $value['spf'],
                    'result_rq' => $value['rf'],
                ];
                 JcCaiji::getInstance()->UpdateJc($v['id'],$data);
            }
            Log::log('info','竞彩结果采集更新成功');
        }catch(Exception $e){
            Log::error('竞彩结果采集错误::'.$e->getMessage());
            return [];
        }


    }
}